package com.xu.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
// @RequestMapping("/hello")
public class RequestMappingController {

    @RequestMapping("/index")
    public String index(){
        // 返回视图名称，即加上配置视图解析器时，指定的前缀和后缀
        return "target";
    }

    // 此时请求映射所映射的请求的请求路径为：/hello/test
    @RequestMapping(
            value = {"/test", "/testRequestMapping"},
            method = {RequestMethod.POST}
    )
    public String success(){
        return "success";
    }

    @RequestMapping(
            value = "/testParamsAndHeaders",
            params = {"username"}
    )
    public String testParamsAndHeaders(){
        return "success";
    }

    @RequestMapping("/testRest/{id}/{username}")
    public String testRest(@PathVariable("id") String id, @PathVariable("username") String username){
        System.out.println("id: " + id + ", username: " + username);
        return "success";
    }

}
